
export const app_mixin = {
	methods: {
		GetQueryString(name) {
			// #ifdef H5
			var reg = new RegExp("(^|&)" + name + "=([^&#]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
			// #endif

			// #ifndef H5
			return null;
			// #endif
		},
		show95Modal(content,title="提示", confirmText = '知道了', confirmFunc = undefined){
			uni.showModal({
				title: title,
				content: content ,
				showCancel:false,
				confirmText: confirmText,
				success: (res) => {
					if (res.confirm) {
						if (confirmFunc !== undefined) {
							confirmFunc()
						} else {

						}
					}
				},
				fail: (err) => {
					console.log("showModal模式 fail失败,", err.errMsg);
					uni.showModal({
						title: "提示",
						content: err.errMsg ,
						showCancel:false,
					})
				},
			})
		},
		goBack: function() {
			uni.navigateBack({});
		},
		goHome() {
			// uni.switchTab({ //字节跳动无法使用这个
			uni.reLaunch({ //兼容字节跳动
				url: "/pages/yqmIndex/yqmIndex",
				fail: () => {
					console.log("跳转失败!!将使用goToPageUrl模式")
					this.goToPageUrl("/pages/yqmIndex/yqmIndex")
				}
			});
		},

		openWebUrl(url) {
			// #ifdef H5
			window.location.href = url
			// #endif

			// #ifndef H5
			this.goToWebUrl(url)
			// #endif


		},

		openWebPayUrl(url) {

			// #ifdef H5
			window.location.href = url
			// #endif

			// #ifdef APP-PLUS
			plus.runtime.openURL(url)
			// #endif

			// #ifdef MP
			this.goToWebUrl(url)
			// #endif

		},
		goToWebUrl(url) {
			uni.navigateTo({
				url: '/pages/webview/index?url=' + url
			});
		},
		switchTabUrl(url) {
			console.log("进入tab切换方法 switchTabUrl 路径不能带参数哦",url);
			// uni.switchTab({ //字节跳动无法使用这个
			uni.reLaunch({ //兼容字节跳动
				url: url,
				fail: (err) => {
					console.log("switchTabUrl模式 跳转失败,", err, url);
					// uni.navigateTo({
					// 	url: url,
					// 	fail: (err) => {
					// 		console.log("navigateTo模式 跳转失败,", err, url);
					// 	}
					// })
				},
				success: (res) => {
					console.log("switchTabUrl模式 success!,", res, url);
				},
				complete:(res)=>{
					console.log("switchTabUrl模式 complete!,", res, url);
				}
			});
		},

		checkLogin() {
			this.user_is_login = uni.getStorageSync('user_is_login') ? true : false;
			if (this.user_is_login == false) {
				uni.reLaunch({
					url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
					success: (res) => {
						uni.$u.toast("请先登录")
					}
				})
				return
			}
		},
		goToPageUrlLogin(url) {
			console.log("goToPageUrlLogin函数 this.user_is_login", this.user_is_login)
			if (this.user_is_login == false) {
				uni.reLaunch({
					url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
					success: (res) => {
						uni.$u.toast("请先登录")
					}
				})
				return
			}else{
				uni.navigateTo({
					url: url,
					fail: (err) => {
						console.log("navigateTo模式 跳转失败,", err, url);
						uni.switchTab({
							url: url,
							fail: () => {
								console.log("switchTab模式 跳转失败,", err, url);
							}
						});
					}
				});
			}
		},
		goToPageUrl(url) {
			uni.navigateTo({
				url: url,
				fail: (err) => {
					console.log("navigateTo模式 跳转失败,", err, url);
					uni.switchTab({
						url: url,
						fail: () => {
							console.log("switchTab模式 跳转失败,", err, url);
						}
					});
				}
			})
		},
		goToPageUrlUserLogin(url) {
			if (this.user_is_login == false) {
				uni.reLaunch({
					url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
					success: (res) => {
						uni.$u.toast("请先登录")
					}
				})

				return
			}else{
				uni.navigateTo({
					url: url,
					fail: (err) => {
						console.log("navigateTo模式 跳转失败,", err, url);
						uni.switchTab({
							url: url,
							fail: () => {
								console.log("switchTab模式 跳转失败,", err, url);
							}
						});
					}
				})
			}
		},
		goToPageUrlReLaunch(url) {
			uni.reLaunch({
				url: url,
				fail: (err) => {
					console.log("reLaunch模式 跳转失败,", err, url);
					uni.switchTab({
						url: url,
						fail: () => {
							console.log("switchTab模式 跳转失败,", err, url);
						}
					});
				}
			})
		},
		copyStr(string_data) {
			console.log("复制功能被触发",string_data);
			// #ifdef H5
			let result = false
			let textarea = document.createElement("textarea")
			textarea.value = string_data
			textarea.readOnly = "readOnly"
			document.body.appendChild(textarea)
			textarea.select() // 选中文本内容
			textarea.setSelectionRange(0, string_data.length)
			result = document.execCommand("copy")
			textarea.remove()
			if (result) {
				uni.showToast({
					title: "已复制到剪贴板"
				})
			} else {
				uni.showToast({
					title: "复制失败,请手动记录"
				})
			}
			// #endif

			// #ifndef H5
			uni.setClipboardData({
				data: string_data,
				success: function() {
					uni.showToast({
						title: "已复制到剪贴板"
					})
				},
				fail: function() {
					uni.showToast({
						title: "复制失败,请手动记录"
					})
				}
			});
			// #endif
		},

		sys_ad_click(ad_item) {
			//ad_item.item  // 1.内部uniapp页面 2.外部webURL  3.跳转小程序
			if (ad_item.item == 1) {
				this.goToPageUrl(ad_item.src)
				return
			}
			if (ad_item.item == 2) {
				this.openWebUrl(ad_item.src2)
				return
			}
			if (ad_item.item == 3) {
				uni.navigateToMiniProgram({
					appId: ad_item.appid
				})
			}
		},
	}

}
